#ifndef __GOFGAME_COMMON_SCOPE_MUTEX_SCOPE_H__
#define __GOFGAME_COMMON_SCOPE_MUTEX_SCOPE_H__

#include <pthread/pthread.h>

namespace gofgame {
	namespace common {
		namespace scope {
			struct MutexScope {
				MutexScope(pthread_mutex_t *mutex) {
					this->mutex = mutex;
					if (mutex) {
						pthread_mutex_lock(mutex);
					}
				}
				~MutexScope() {
					pthread_mutex_t *mutex = this->mutex;
					if (mutex) {
						this->mutex = nullptr;
						pthread_mutex_unlock(mutex);
					}
				}
				pthread_mutex_t *mutex;
			};
		}
	}
}

#endif //__GOFGAME_COMMON_SCOPE_MUTEX_SCOPE_H__